package com.joizhang.nettylecture.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * File lock
 *
 * @author joizhang
 */
public class NioTest10 {

    public static void main(String[] args) throws IOException {
        try (RandomAccessFile randomAccessFile = new RandomAccessFile("NioTest10.txt", "rw")) {
            FileChannel fileChannel = randomAccessFile.getChannel();
            FileLock fileLock = fileChannel.lock(3, 6,true);

            System.out.println("valid: " + fileLock.isValid());
            System.out.println("Lock type: " + fileLock.isShared());

            fileLock.release();
        }
    }

}
